<?php
namespace App\Commen;

use Symfony\Component\DependencyInjection\ContainerInterface;

class AdminCommen
{
    private $container;
    private $jobConn;
    /** @var  \Monolog\Logger */
    private $logger;

    /**
     * UserCommen constructor.
     * @param ContainerInterface $container
     * @param $logger
     */
    public function __construct($container, $logger)
    {
        $this->container = $container;
        $this->jobConn = $container->get('doctrine.dbal.customer_connection');
        $this->logger = $logger;
    }

    /**
     * 验证账号密码 用户角色
     * @param $username
     * @param $password
     * @return array
     */
    public function getUser($username, $password)
    {
        $having = $this->jobConn->fetchColumn(
            "SELECT id from app_admin where username=:username and password=:password",
            array('username' => $username, 'password' => $password)
        );
        if (empty($having)) {
        return array();
    }

        return array(
            'user_id' => $having,
            'role' => 'ROLE_ADMIN'
        );
    }
}